package demoMod.invincibleOne.powers;

import basemod.ReflectionHacks;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.actions.unique.SummonGremlinAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;
import demoMod.invincibleOne.InvincibleOneMod;

import java.util.UUID;

public class ConscriptionPower extends AbstractPower {
    public static final String POWER_ID = InvincibleOneMod.makeID("ConscriptionPower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;
    public static AbstractMonster[] gremlins = new AbstractMonster[100];
    private static int idOffset = 0;

    public ConscriptionPower(AbstractCreature owner, int amount) {
        this.owner = owner;
        this.ID = POWER_ID + idOffset;
        idOffset++;
        this.name = NAME;
        this.amount = amount;
        this.updateDescription();
        loadRegion("painfulStabs");
        this.type = PowerType.DEBUFF;
        this.isTurnBased = true;
    }

    @Override
    public void onInitialApplication() {
        atStartOfTurn();
    }

    @Override
    public void updateDescription() {
        this.description = String.format(DESC[0], this.amount);
    }

    @Override
    public void atStartOfTurn() {
        if (amount <= 1) {
            this.flash();
            addToBot(new SummonGremlinAction(gremlins));
            addToBot(new AbstractGameAction() {
                @Override
                public void update() {
                    for (AbstractMonster monster : gremlins) {
                        if (monster != null && !monster.isDeadOrEscaped() && !(ReflectionHacks.getPrivate(monster, AbstractMonster.class, "move") == null)) {
                            monster.createIntent();
                        }
                    }
                    isDone = true;
                }
            });
        }
        addToBot(new ReducePowerAction(owner, owner, this, 1));
    }
}
